/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-24 15:38:32
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2023-11-24 16:11:29
 * @FilePath: \WingsUpdater-main\inc\DataTransmission\IDataTransmission.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#pragma once
#include <mutex>
#include <queue>
#include <memory>
#include <vector>
#include "Result.h"
#include <functional>
#include <initializer_list>
#include <condition_variable>
#include "WingsTcpUdpProto.h"

// macro
#define DATA_TRANSMISSION_UDP                                                                                                                                 0
#define DATA_TRANSMISSION_TCP                                                                                                                                 1

typedef struct{
        bool uBoot = false;
        uint8_t uState;
        uint32_t uSize;
        uint32_t uCrc32;
        uint32_t uNext;
        std::string fileName;//压缩包名
        std::vector<uint8_t> uBuffer;
}system_para_t;
// class
class IDataTransmission 
{
public:
    using AsyncFuncType = std::function<void(const void *src, const size_t size)>;
public:
    static std::shared_ptr<IDataTransmission> create(const int type = DATA_TRANSMISSION_UDP);
    virtual ~IDataTransmission() = default;
    virtual Result init(const std::initializer_list<void *> attr = {});
    virtual Result transmit(const void *src, const size_t size) = 0;
    Result transmit(const std::vector<uint8_t> &src);
    virtual void asyncRecv(const void *src, const size_t size);
    bool wait(const int64_t timeout = 3000);
    size_t available();
    void *take();
    virtual void release(const void *item) = 0;
    virtual void *dataResolver(const std::vector<uint8_t> &buf,WingsInternalWrapper &src); 
protected:
    IDataTransmission() = default;
protected:
    std::mutex m_queMtx;
    std::condition_variable m_queCond;
    std::queue<void *> m_recvQue;
    static const size_t m_queMaxSize;
};
